package com.huanming.dsjc.modular.goods.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.huanming.dsjc.common.persistence.model.Dept;
import com.huanming.dsjc.modular.goods.dao.GoodsCategoryMapper;
import com.huanming.dsjc.modular.goods.entity.GoodsCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huanming.dsjc.modular.goods.service.IGoodsCategoryService;

import java.util.List;

/**
 * 商品分类Service
 *
 * @author xufei
 * @Date 2018-01-17 15:15:26
 */
@Service
public class GoodsCategoryServiceImpl implements IGoodsCategoryService {

    @Autowired
    private GoodsCategoryMapper goodsCategoryMapper;

    @Override
    public void deleteCategory(Integer categoryId) {
        GoodsCategory goodsCategory = goodsCategoryMapper.selectById(categoryId);

        Wrapper<GoodsCategory> wrapper = new EntityWrapper<>();
        wrapper = wrapper.like("pids", "%[" + goodsCategory.getId() + "]%");
        List<GoodsCategory> subDepts = goodsCategoryMapper.selectList(wrapper);
        for (GoodsCategory temp : subDepts) {
            temp.deleteById();
        }
        goodsCategoryMapper.deleteById(categoryId);
    }
}
